package cn.afactory.tygz.ui.base.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.afactory.tygz.R;
import cn.afactory.tygz.ui.base.entity.CommunityInfo;

/**
 * Created by Kenneth on 15/9/12.
 */
public class CommunityListAdapter extends BaseListAdapter<CommunityInfo, CommunityListAdapter.CommunityViewHolder> {

    public CommunityListAdapter(Context context) {
        super(context);
    }

    public CommunityListAdapter(Context context, List<CommunityInfo> listData) {
        super(context, listData);
    }

    @Override
    public View newView(int position, LayoutInflater inflater, ViewGroup parent) {
        return inflater.inflate(R.layout.fg_community_list_item, null);
    }

    @Override
    public CommunityViewHolder onViewHolderCreate(int position, View view) {
        CommunityViewHolder viewHolder = new CommunityViewHolder();
        viewHolder.communityIcon = (ImageView)view.findViewById(R.id.commuinty_list_icon);
        viewHolder.communityTitle = (TextView)view.findViewById(R.id.commuinty_list_title);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(int position, CommunityInfo itemData, CommunityViewHolder communityViewHolder) {
        communityViewHolder.communityIcon.setImageResource(itemData.icon);
        communityViewHolder.communityTitle.setText(itemData.name);
    }

    public class CommunityViewHolder extends BaseListAdapter.ViewHolder {
        ImageView communityIcon;
        TextView communityTitle;
    }
}
